package com.automannn.practice.mybatis.statementHandler;

import org.apache.ibatis.builder.StaticSqlSource;
import org.apache.ibatis.executor.Executor;
import org.apache.ibatis.executor.SimpleExecutor;
import org.apache.ibatis.executor.result.DefaultResultHandler;
import org.apache.ibatis.executor.statement.SimpleStatementHandler;
import org.apache.ibatis.executor.statement.StatementHandler;
import org.apache.ibatis.mapping.BoundSql;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.mapping.SqlCommandType;
import org.apache.ibatis.mapping.SqlSource;
import org.apache.ibatis.session.Configuration;
import org.apache.ibatis.session.ResultHandler;
import org.apache.ibatis.session.RowBounds;
import org.apache.ibatis.transaction.Transaction;

import java.sql.SQLException;
import java.sql.Statement;

/**
 * @author chenkh
 * @time 2021/11/16 15:52
 */
public class StatementHandlerTest {
    public static void main(String[] args) throws SQLException {

        Configuration configuration = new Configuration();
        Transaction transaction =null;

        Executor executor= new SimpleExecutor(configuration,transaction);

        SqlSource sqlSource =new StaticSqlSource(configuration,"select * from person");

        Object params = new Object();

        BoundSql boundSql = sqlSource.getBoundSql(params);

        MappedStatement mappedStatement = new MappedStatement.Builder(configuration,"test",sqlSource, SqlCommandType.SELECT).build();

        ResultHandler resultHandler = new DefaultResultHandler();

        StatementHandler statementHandler = new SimpleStatementHandler(executor,mappedStatement,params, RowBounds.DEFAULT,resultHandler,boundSql);

        Statement statement=null;
        statementHandler.parameterize(statement);
    }
}
